const baseUrl = 'http://192.168.18.6:2200' // 替换为你的 API 基础 URL
import Storage from './storage'
const request = (url, method = 'GET', data = {}, header = {}) => {
    return new Promise((resolve, reject) => {
        const token = Storage.get('token') || null
        wx.request({
            url: `${baseUrl}${url}`,
            method: method,
            data: data,
            header: {
                'Content-Type': 'application/json',
                'Cy-Token': token,
                'CY-PREPROCESSING':true,
                'Cy-Product-Type': 'visitor',
                'Authorization':token,
                ...header
            },
            success: (res) => {
                if (res.statusCode === 200) {
                    if (res.data.code !== 1) {
                        wx.showToast({
                            title: res.data.message,
                            icon: 'error'
                        })
                        return
                    }
                    resolve(res.data)
                } else {
                    reject(res.data)
                }
            },
            fail: (error) => {
                reject(error)
            }
        })
    })
}
module.exports = {
    request,
    baseUrl
}
